﻿Public Class frmEditor
    Public associateTab As GrayIris.Utilities.UI.Controls.YaTabPage
    Public isChanged As Boolean = False
    Public fileName As String = ""
    Public fullFileName As String = ""

    Private lastMeasuredLineMargin As Integer = -1

    Public Sub SetFileChange(ByVal bool As Boolean)
        If bool Then
            associateTab.Text = "*" & fileName
        Else
            associateTab.Text = fileName
        End If

        isChanged = bool
    End Sub

    Private Sub UpdateLineColStatus()
        Dim startLine As ScintillaNET.Line = txtCode.Selection.Range.StartingLine
        frmMain.lbStatusLine.Text = "Line: " & startLine.Number + 1
        frmMain.lbStatusCol.Text = "Col: " & startLine.SelectionStartPosition - startLine.StartPosition + 1
    End Sub

    Private Sub txtCode_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCode.GotFocus
        UpdateLineColStatus()
    End Sub

    Private Sub txtCode_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCode.SelectionChanged
        UpdateLineColStatus()
    End Sub

    Private Sub txtCode_TextDeleted(ByVal sender As Object, ByVal e As ScintillaNET.TextModifiedEventArgs) Handles txtCode.TextDeleted
        TextChange()
    End Sub

    Private Sub txtCode_TextInserted(ByVal sender As Object, ByVal e As ScintillaNET.TextModifiedEventArgs) Handles txtCode.TextInserted
        TextChange()
    End Sub

    Private Sub TextChange()
        Dim lineDigitLength As Integer = txtCode.Lines.Count.ToString.Length
        If lastMeasuredLineMargin <> lineDigitLength Then
            lastMeasuredLineMargin = lineDigitLength
            txtCode.Margins(0).Width = TextRenderer.MeasureText("999999999".Substring(0, lineDigitLength), txtCode.Font).Width
        End If

        If isChanged = False Then
            SetFileChange(True)
        End If
    End Sub
End Class